package question1.wrong;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

/**
 * 有一批任务需要处理，单个任务耗时事件不确定，请最短时间内处理完这批任务。
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        plan();
    }


    // https://www.cnblogs.com/yangzhenlong/p/8359875.html ConcurrentLinkedQueue使用和方法介绍
    public static List<Task> generateTaskList(int taskCount) {
        List<Task> taskList = new ArrayList<>();
//        IntStream.range(0, taskCount).mapToObj(Task::new).forEach(taskList::add);
        IntStream.range(0, taskCount)
                .mapToObj(i -> new Task(i))
                .forEach(task -> taskList.add(task));
        return taskList;
    }

    public static void plan() throws InterruptedException {
        List<Task> taskList = generateTaskList(30);
        Thread t1 = new Thread(new Worker(1, taskList));
        Thread t2 = new Thread(new Worker(2, taskList));
        Thread t3 = new Thread(new Worker(3, taskList));

        t1.start();
        t2.start();
        t3.start();

        t1.join();
        t2.join();
        t3.join();

    }

}
